#include <mysql/mysql.h>
#include <string.h>
#include <stdio.h>

int insertLog(int userID, char *cmd)
{
	MYSQL *conn;
	char *server = "localhost";
	char *user = "root";
	char *password = "1234";
	char *database = "netdisk";//要访问的数据库名称
    char query[200] = {0};
    char buf[]="insert into log (user_id,cmd) values";
    sprintf(query, "%s (%d, '%s')", buf, userID, cmd);
	int queryResult;

	conn = mysql_init(NULL);

	if(!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0))
	{
		printf("Error connecting to database: %s\n", mysql_error(conn));
	}
    else
    {
		/* printf("Connected...\n"); */
	}

	queryResult = mysql_query(conn, query);
	if(queryResult)
	{
		printf("Error making query:%s\n", mysql_error(conn));
	}
    else
    {
		/* printf("insert log success\n"); */
	}
	mysql_close(conn);

	return 0;
}
